﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GmaWebService.Interfaces;
using System.ServiceModel;
using WebMediaPortal.Code;
using TV4Home.Server.TVEInteractionLibrary.Interfaces;

namespace WebMediaPortal.Services
{
    public static class WebServices
    {
        private static IMediaAccessService _service;
        private static ITVEInteraction _tvService;
        public static IMediaAccessService MediaAccessService
        {
            get
            {
                if (_service == null || ((ICommunicationObject)_service).State == CommunicationState.Faulted)
                {
                    try
                    {
                        _service = ChannelFactory<IMediaAccessService>.CreateChannel(new NetNamedPipeBinding() { MaxReceivedMessageSize = 10000000 }, new EndpointAddress("net.pipe://localhost/GmaWebService/MediaAccessService"));

                    }
                    catch (Exception ex)
                    {

                        Log.Error("Exception in ServiceInstance", ex);
                    }
                }
                return _service;
            }
        }
       

        public static ITVEInteraction TVService
        {
            get
            {
                if (_tvService == null || ((ICommunicationObject)_tvService).State == CommunicationState.Faulted)
                {
                    _tvService = ChannelFactory<ITVEInteraction>.CreateChannel(new NetNamedPipeBinding() { MaxReceivedMessageSize = 10000000 }, new EndpointAddress("net.pipe://localhost/TV4Home.Server.CoreService/TVEInteractionService"));
                }

                return _tvService;
            }
        }
    }
}